package homeactivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import com.yztc.thinkpad.mandemo.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import homeactivity.PingpaiFragment.FirstFragment;
import homeactivity.bean.PingpaiContentBean;
import homeactivity.contans.PingpaiUrl;
import singleadapter.TablayoutFragmentAdapter;

/**
 * Created by Administrator on 2016/10/11.
 */
public class PingPaiOneActivity extends AppCompatActivity{
    private  TextView mTitle;
    private ImageView mIvBack;
    private TabLayout mTablayout;
    private ViewPager mVp;
    private String mBrandID;
    private String mTitleName;
    private List<Fragment> fragmentList = new ArrayList<>();
    private String title[] = {"上衣", "裤子"};
    private TablayoutFragmentAdapter adapter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pingpai_activity);
        ButterKnife.bind(this);
        initData();//初始化控件
        initLists();//添加Fragment
        for (int i = 0; i < title.length; i++) {
            mTablayout.addTab(mTablayout.newTab().setText(title[i]));
        }
        mVp.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTablayout));
        mTablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mVp.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });
    }

    private void initLists() {
        fragmentList.add(new FirstFragment());
        fragmentList.add(new FirstFragment());
        adapter = new TablayoutFragmentAdapter(getSupportFragmentManager(), fragmentList);
        mVp.setAdapter(adapter);
    }
    private void initData() {
        mIvBack = (ImageView) findViewById(R.id.pingpai_back);
        mTablayout = (TabLayout) findViewById(R.id.pingpai_layout);
        mTitle= (TextView) findViewById(R.id.pingpai_titleName);
        mVp = (ViewPager) findViewById(R.id.pingpai_vp);
        Intent intent=getIntent();
        mBrandID=intent.getStringExtra("BrandID");
//        Log.i("tag","----->"+mBrandID);
        mTitleName=intent.getStringExtra("titleName");
        mTitle.setText(mTitleName);
//        String path= PingpaiUrl.URLHEAD+mBrandID+PingpaiUrl.URLFOOT;
        FirstFragment fragment1 = new FirstFragment();
        Bundle bundle = new Bundle();
        bundle.putString("mBrandID",mBrandID);
        fragment1.setArguments(bundle);
        Log.i("tag","--------->"+mBrandID);
    }
}
